<% layout('/layouts/default.html', {title: '产品档案管理', libs: ['validate','dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header with-border">
			<div class="box-title">
				<i class="fa icon-note"></i> ${text(stProductRecord.isNewRecord ? '新增产品档案' : '编辑产品档案')}
			</div>
			<div class="box-tools pull-right">
				<button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
			</div>
		</div>
		<#form:form id="inputForm" model="${stProductRecord}" action="${ctx}/st/stProductRecord/save" method="post" class="form-horizontal">
			<div class="box-body">
				<div class="form-unit">${text('基本信息')}</div>
				<#form:hidden path="id"/>
				<div class="row">
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('产品名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="productName" maxlength="20" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('产品编号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="productCode" maxlength="20" class="form-control" readonly="true"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('产品性质')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="productQuality" dictType="st_product_quality" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('产品类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
<!--								st_product_type -->
								<#form:select path="productType" items="${listMaterialType}" itemLabel="typeName" itemValue="code" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('动物种类')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="animalCategory" dictType="st_animal_category" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('原料编码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="rawMaterialCode" maxlength="20" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('比例')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="percentIn" dictType="st_product_percent" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('型号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="model" dictType="st_product_model" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('序号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="number" dictType="st_product_number" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('客户名称')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="customName" items="${listCustomRecord}" itemLabel="companySimpleName" itemValue="id" blankOption="true" class="form-control" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('产品系列')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="productSeries" dictType="st_product_series" blankOption="true" class="form-control digits" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('包装规格')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="packSize" maxlength="10" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('计量单位')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="calcUnit" maxlength="36" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('辅助单位')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="supUnit" maxlength="36" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('规格型号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="specification" maxlength="20" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('生产厂家')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="productMaker" dictType="st_product_maker" blankOption="true" class="form-control digits" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('默认仓位')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="defaultWarehouse" maxlength="36" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('条码号')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="barCode" maxlength="20" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最低库存')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="lowInventory" class="form-control number"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('最高库存')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="highInventory" class="form-control number"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('参考成本')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="referenceCost" class="form-control number"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('参考进价')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="referenceInPrice" class="form-control number"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('参考售价')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="referenceOutPrice" class="form-control number"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required">*</span> ${text('检验类型')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="checkType" dictType="st_check_type" blankOption="true" class="form-control digits required" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('保质期')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="savedType" maxlength="3" class="form-control digits"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('有效')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:checkbox path="effect" label="&nbsp;" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('批号管理')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:checkbox path="batchManage" label="&nbsp;" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('审批状态')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:select path="approveState" dictType="st_approve_state" blankOption="true" class="form-control digits" />
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('审批人编码')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="approveManCode" maxlength="20" class="form-control"/>
							</div>
						</div>
					</div>
					<div class="col-xs-6">
						<div class="form-group">
							<label class="control-label col-sm-4" title="">
								<span class="required hide">*</span> ${text('审批人')}：<i class="fa icon-question hide"></i></label>
							<div class="col-sm-8">
								<#form:input path="approveManName" maxlength="5" class="form-control"/>
							</div>
						</div>
					</div>
				</div>
				<h4 class="form-unit">${text('原始配方')}</h4>
				<div class="ml10 mr10">
					<table id="stFormulaDataGrid"></table>
					<% if (hasPermi('st:stProductRecord:edit')){ %>
						<a href="#" id="stFormulaDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>
					<% } %>
				</div>
				<h4 class="form-unit">${text('生产配方')}</h4>
				<div class="ml10 mr10">
					<table id="stFormulaNameDataGrid"></table>
					<% if (hasPermi('st:stProductRecord:edit')){ %>
<!--						<a href="#" id="stFormulaNameDataGridAddRowBtn" class="btn btn-primary btn-sm mt10 mb10"><i class="fa fa-plus"></i> ${text('增行')}</a>-->
					<% } %>
				</div>
			</div>
			<div class="box-footer">
				<div class="row">
					<div class="col-sm-offset-2 col-sm-10">
						<% if (hasPermi('st:stProductRecord:edit')){ %>
							<button type="submit" class="btn btn-sm btn-primary" id="btnSubmit"><i class="fa fa-check"></i> ${text('保 存')}</button>&nbsp;
						<% } %>
						<button type="button" class="btn btn-sm btn-default" id="btnCancel" onclick="js.closeCurrentTabPage()"><i class="fa fa-reply-all"></i> ${text('关 闭')}</button>
					</div>
				</div>
			</div>
		</#form:form>
	</div>
</div>
<% } %>
<script>
//初始化原始配方DataGrid对象
$("#stFormulaDataGrid").dataGrid({

	data: ${toJson(stProductRecord.stFormulaList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'id', editable:true, hidden:true},
		{header:'${text("原料名称")}', name:'materialName', width:150,
			editable:true, edittype:'select', editoptions:{'class':'form-control',
				items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('st_product_makeup')}),
				itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
					$(element).select2().on("change",function(){$(this).resetValid()});
				}
			}
		},
		{header:'${text("每公斤产品成分值")}', name:'elementValue', width:150, editable:true, edittype:'text', editoptions:{'class':'form-control number'}},
		{header:'${text("国际单位")}', name:'unit', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'36', 'class':'form-control'}},
		{header:'${text("备注")}', name:'remarks', width:150, editable:true, edittype:'textarea', editoptions:{'maxlength':'500', 'class':'form-control', 'rows':'1'}},
		{header:'${text("产品id")}', name:'productId.id', editable:true, hidden:true},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
			if (val == 'new'){
				actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#stFormulaDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}else{
				actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#stFormulaDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			}
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 1,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#stFormulaDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'stFormulaList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,id,materialName,elementValue,unit,remarks,productId.id,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
//初始化生产配方DataGrid对象
$("#stFormulaNameDataGrid").dataGrid({

	data: ${toJson(stProductRecord.stFormulaNameList)},
	datatype: "local", // 设置本地数据
	autoGridHeight: function(){return 'auto'}, // 设置自动高度
	
	// 设置数据表格列
	columnModel: [
		{header:'状态', name:'status', editable:true, hidden:true},
		{header:'主键', name:'id', editable:true, hidden:true},
		{header:'${text("配方编码")}', name:'code', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'20', 'class':'form-control'}},
		// {header:'${text("使用状态")}', name:'useState', width:100,
		// 	editable:true, edittype:'select', editoptions:{'class':'form-control digits',
		// 		items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('st_use_status')}),
		// 		itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
		// 			$(element).select2().on("change",function(){$(this).resetValid()});
		// 		}
		// 	}
		// },
		// {header:'${text("产品 id")}', name:'productId.id', editable:true, hidden:true},
		// {header:'${text("审批状态")}', name:'approveState', width:100,
		// 	editable:true, edittype:'select', editoptions:{'class':'form-control digits',
		// 		items: $.merge([{dictLabel:'&nbsp;',dictValue:''}], ${@DictUtils.getDictListJson('st_approve_state')}),
		// 		itemLabel: 'dictLabel', itemValue: 'dictValue', dataInit: function(element){
		// 			$(element).select2().on("change",function(){$(this).resetValid()});
		// 		}
		// 	}
		// },
		// {header:'${text("审批人编码")}', name:'approveManCode', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'20', 'class':'form-control'}},
		// {header:'${text("审批人")}', name:'approveManName', width:150, editable:true, edittype:'text', editoptions:{'maxlength':'5', 'class':'form-control'}},
		{header:'${text("备注信息")}', name:'remarks', width:150, editable:true, edittype:'textarea', editoptions:{'maxlength':'500', 'class':'form-control', 'rows':'1'}},
		{header:'${text("操作")}', name:'actions', width:80, sortable:false, fixed:true, formatter: function(val, obj, row, act){
			var actions = [];
			// if (val == 'new'){
			// 	actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#stFormulaNameDataGrid\').dataGrid(\'delRowData\',\''+obj.rowId+'\')});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			// }else{
			// 	actions.push('<a href="#" onclick="js.confirm(\'${text("你确认要删除这条数据吗？")}\', function(){$(\'#stFormulaNameDataGrid\').dataGrid(\'setRowData\',\''+obj.rowId+'\',null,{display:\'none\'});$(\'#'+obj.rowId+'_status\').val(\''+Global.STATUS_DELETE+'\');});return false;"><i class="fa fa-trash-o"></i></a>&nbsp;');
			// }
			return actions.join('');
		}, editoptions: {defaultValue: 'new'}}
	],
	
	// 编辑表格参数
	editGrid: true,				// 是否是编辑表格
	editGridInitRowNum: 0,		// 编辑表格的初始化新增行数
	editGridAddRowBtn: $('#stFormulaNameDataGridAddRowBtn'),	// 子表增行按钮
	editGridAddRowInitData: {id: '', status: Global.STATUS_NORMAL},	// 新增行的时候初始化的数据
	
	// 编辑表格的提交数据参数
	editGridInputFormListName: 'stFormulaNameList', // 提交的数据列表名
	editGridInputFormListAttrs: 'status,id,code,useState,productId.id,approveState,approveManCode,approveManName,createBy,createDate,updateBy,updateDate,remarks,', // 提交数据列表的属性字段
	
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
</script>
<script>
$("#inputForm").validate({
	submitHandler: function(form){
		js.ajaxSubmitForm($(form), function(data){
			js.showMessage(data.message);
			if(data.result == Global.TRUE){
				js.closeCurrentTabPage(function(contentWindow){
					contentWindow.page();
				});
			}
		}, "json");
    }
});
</script>